<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/jsp/common/head.jsp"%>

<script type="text/javascript">
    window.onload=function (){
        var add=  document.getElementById("add");
        //获取表单 把button变成submit
        // var form=document.getElementsByTagName('form')[0];"
        var form=document.getElementById("billForm");
        // add.onclick=function (){
        //   // form.submit();
        // }

    }
 function  fanhui(){
     window.history.back();
 }


    function  check(){

        var billCode=document.getElementById("billCode");//获取商品编码
        var productName=document.getElementById("productName");//商品名称
        var productUnit=document.getElementById("productUnit");//商品单位
        var  productCount=document.getElementById("productCount");//商品数量
        var totalPrice=document.getElementById("totalPrice");
        var  providerId=document.getElementById("providerId");
        var  isPayment=document.getElementsByName("isPayment");//这是单选框
        for (var i=0;i<isPayment.length;i++){
         if (isPayment[i].checked){
             isPayment=isPayment[i].value;
         }
        }
        var bm=document.getElementById("bmerror");
        var mc=document.getElementById("mcerror");
        var dw=document.getElementById("dwerror");
        var sl=document.getElementById("slerror");
        var je=document.getElementById("jeerror");
        var gh=document.getElementById("gherror");


       if (billCode.value==""){
           bm.innerHTML="请输入商品编码";
               return false;
       }else if(billCode.value.includes(" ")){//是否含有空格 方法二 billCode.value.indexOf(" ")!= -1
           bm.innerHTML="商品编码不能存在空格";
           billCode.style.color="red";
           return false;
       }else{
           bm.innerHTML="";
       }

       if (productName.value==""){
           mc.innerHTML="请输入商品名称";
           return false;
       }else if (productName.value.includes(" ")){
           mc.innerHTML="商品名称不能存在空格";
           productName.style.color="red";
           return false;
       }else {
           productName.style.color="black";
           mc.innerHTML="";
       }


        if (productUnit.value==""){
            dw.innerHTML="请输入商品单位";
            return false;
        }else{
            dw.innerHTML="";
        }
        if (productCount.value==""){
            sl.innerHTML="请输入商品数量";
            return false;
        }else{
            sl.innerHTML="";
        }

        if (totalPrice.value==""){
            je.innerHTML="请输入商品总金额";
            return false;
        }else {
            je.innerHTML="";
        }
        if (providerId.value=="0"){
           gh.innerHTML="请选择供货商";
            return false;
        }else {
            gh.innerHTML="";
        }

      document.getElementById("billForm").submit();


    }

</script>


<div class="right">
     <div class="location">
         <strong>你现在所在的位置是:</strong>
         <span>订单管理页面 >> 订单添加页面</span>
     </div>
     <div class="providerAdd">
         <form id="billForm" name="billForm" method="post" action="${pageContext.request.contextPath }/jsp/bill.do"  >
             <!--div的class 为error是验证错误，ok是验证成功-->
             <input type="hidden" name="method" value="add">
             <div class="">
                 <label for="billCode">订单编码：</label>
                 <input type="text" name="billCode" class="text" id="billCode" value="">
				 <!-- 放置提示信息 -->
                 <span id="bmerror"   style="color: red"  ></span>

             </div>
             <div>
                 <label for="productName">商品名称：</label>
                 <input type="text" name="productName" id="productName" value="">
                 <span id="mcerror"   style="color: red"  ></span>


             </div>
             <div>
                 <label for="productUnit">商品单位：</label>
                 <input type="text" name="productUnit" id="productUnit" value="">
                 <span id="dwerror"   style="color: red"  ></span>
             </div>
             <div>
                 <label for="productCount">商品数量：</label>
                 <input type="text" name="productCount" id="productCount" value="">
                 <span id="slerror"   style="color: red"  ></span>
             </div>
             <div>
                 <label for="totalPrice">总金额：</label>
                 <input type="text" name="totalPrice" id="totalPrice" value="">
                 <span id="jeerror"   style="color: red"  ></span>
             </div>
             <div>
                 <label >供应商：</label>
                 <select name="providerId" id="providerId">
                     <option value="0">--请选择--</option>
                     <c:forEach  var="provider" items="${providerListadd}">
                         <option value="${provider.proName}">${provider.proName}</option>
                     </c:forEach>

		         </select>
                 <span id="gherror"   style="color: red"  ></span>
             </div>
             <div>
                 <label >是否付款：</label>
                 <input type="radio" name="isPayment"   value="1" checked="checked">未付款
				 <input type="radio" name="isPayment"   value="2" >已付款
             </div>
             <div class="providerAddBtn">
                  <input type="button" name="add" id="add" value="保存"  onclick="check()">
				  <input type="button" id="back" name="back" value="返回"  onclick="fanhui()">
                 ${error}
             </div>
         </form>
     </div>
 </div>
</section>
<%@include file="/jsp/common/foot.jsp" %>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/billadd.js"></script>